/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author owtee
 */
@Entity
@Table(name = "jobs")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Jobs.findAll", query = "SELECT j FROM Jobs j"),
    @NamedQuery(name = "Jobs.findByJobId", query = "SELECT j FROM Jobs j WHERE j.jobId = :jobId"),
    @NamedQuery(name = "Jobs.findByRequestDate", query = "SELECT j FROM Jobs j WHERE j.requestDate = :requestDate"),
    @NamedQuery(name = "Jobs.findByExpectDate", query = "SELECT j FROM Jobs j WHERE j.expectDate = :expectDate"),
    @NamedQuery(name = "Jobs.findByUrgentDate", query = "SELECT j FROM Jobs j WHERE j.urgentDate = :urgentDate"),
    @NamedQuery(name = "Jobs.findByRemark", query = "SELECT j FROM Jobs j WHERE j.remark = :remark"),
    @NamedQuery(name = "Jobs.findByMsgActionDate", query = "SELECT j FROM Jobs j WHERE j.msgActionDate = :msgActionDate"),
    @NamedQuery(name = "Jobs.findByMsgRemark", query = "SELECT j FROM Jobs j WHERE j.msgRemark = :msgRemark"),
    @NamedQuery(name = "Jobs.findByFinishDate", query = "SELECT j FROM Jobs j WHERE j.finishDate = :finishDate"),
    @NamedQuery(name = "Jobs.findByEmployMsgFlag", query = "SELECT j FROM Jobs j WHERE j.employMsgFlag = :employMsgFlag"),
    @NamedQuery(name = "Jobs.findByActiveFlag", query = "SELECT j FROM Jobs j WHERE j.activeFlag = :activeFlag"),
    @NamedQuery(name = "Jobs.findByCreateUser", query = "SELECT j FROM Jobs j WHERE j.createUser = :createUser"),
    @NamedQuery(name = "Jobs.findByCreateDate", query = "SELECT j FROM Jobs j WHERE j.createDate = :createDate"),
    @NamedQuery(name = "Jobs.findByModifyUser", query = "SELECT j FROM Jobs j WHERE j.modifyUser = :modifyUser"),
    @NamedQuery(name = "Jobs.findByModifyDate", query = "SELECT j FROM Jobs j WHERE j.modifyDate = :modifyDate")})
public class Jobs implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "Job_Id")
    private String jobId;
    @Column(name = "Request_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date requestDate;
    @Column(name = "Expect_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date expectDate;
    @Column(name = "Urgent_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date urgentDate;
    @Size(max = 255)
    @Column(name = "Remark")
    private String remark;
    @Column(name = "Msg_Action_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date msgActionDate;
    @Size(max = 255)
    @Column(name = "Msg_Remark")
    private String msgRemark;
    @Column(name = "Finish_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date finishDate;
    @Column(name = "Employ_Msg_Flag")
    private Boolean employMsgFlag;
    @Column(name = "Active_Flag")
    private Boolean activeFlag;
    @Size(max = 10)
    @Column(name = "Create_User")
    private String createUser;
    @Column(name = "Create_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    @Size(max = 10)
    @Column(name = "Modify_User")
    private String modifyUser;
    @Column(name = "Modify_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifyDate;
    @JoinColumn(name = "Period_Id", referencedColumnName = "Period_Id")
    @ManyToOne(optional = false)
    private JobPeriod periodId;
    @JoinColumn(name = "Msg_User", referencedColumnName = "User_Id")
    @ManyToOne(optional = false)
    private Users msgUser;
    @JoinColumn(name = "Request_User", referencedColumnName = "User_Id")
    @ManyToOne(optional = false)
    private Users requestUser;
    @JoinColumn(name = "Status_Id", referencedColumnName = "Status_Id")
    @ManyToOne(optional = false)
    private JobStatus statusId;
    @JoinColumn(name = "Con_Id", referencedColumnName = "Con_Id")
    @ManyToOne(optional = false)
    private Contact conId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "jobId")
    private Collection<JobStatusStatement> jobStatusStatementCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "jobId")
    private Collection<JobDetails> jobDetailsCollection;

    public Jobs() {
    }

    public Jobs(String jobId) {
        this.jobId = jobId;
    }

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public Date getRequestDate() {
        return requestDate;
    }

    public void setRequestDate(Date requestDate) {
        this.requestDate = requestDate;
    }

    public Date getExpectDate() {
        return expectDate;
    }

    public void setExpectDate(Date expectDate) {
        this.expectDate = expectDate;
    }

    public Date getUrgentDate() {
        return urgentDate;
    }

    public void setUrgentDate(Date urgentDate) {
        this.urgentDate = urgentDate;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getMsgActionDate() {
        return msgActionDate;
    }

    public void setMsgActionDate(Date msgActionDate) {
        this.msgActionDate = msgActionDate;
    }

    public String getMsgRemark() {
        return msgRemark;
    }

    public void setMsgRemark(String msgRemark) {
        this.msgRemark = msgRemark;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public Boolean getEmployMsgFlag() {
        return employMsgFlag;
    }

    public void setEmployMsgFlag(Boolean employMsgFlag) {
        this.employMsgFlag = employMsgFlag;
    }

    public Boolean getActiveFlag() {
        return activeFlag;
    }

    public void setActiveFlag(Boolean activeFlag) {
        this.activeFlag = activeFlag;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getModifyUser() {
        return modifyUser;
    }

    public void setModifyUser(String modifyUser) {
        this.modifyUser = modifyUser;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public JobPeriod getPeriodId() {
        return periodId;
    }

    public void setPeriodId(JobPeriod periodId) {
        this.periodId = periodId;
    }

    public Users getMsgUser() {
        return msgUser;
    }

    public void setMsgUser(Users msgUser) {
        this.msgUser = msgUser;
    }

    public Users getRequestUser() {
        return requestUser;
    }

    public void setRequestUser(Users requestUser) {
        this.requestUser = requestUser;
    }

    public JobStatus getStatusId() {
        return statusId;
    }

    public void setStatusId(JobStatus statusId) {
        this.statusId = statusId;
    }

    public Contact getConId() {
        return conId;
    }

    public void setConId(Contact conId) {
        this.conId = conId;
    }

    @XmlTransient
    public Collection<JobStatusStatement> getJobStatusStatementCollection() {
        return jobStatusStatementCollection;
    }

    public void setJobStatusStatementCollection(Collection<JobStatusStatement> jobStatusStatementCollection) {
        this.jobStatusStatementCollection = jobStatusStatementCollection;
    }

    @XmlTransient
    public Collection<JobDetails> getJobDetailsCollection() {
        return jobDetailsCollection;
    }

    public void setJobDetailsCollection(Collection<JobDetails> jobDetailsCollection) {
        this.jobDetailsCollection = jobDetailsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (jobId != null ? jobId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Jobs)) {
            return false;
        }
        Jobs other = (Jobs) object;
        if ((this.jobId == null && other.jobId != null) || (this.jobId != null && !this.jobId.equals(other.jobId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Jobs[ jobId=" + jobId + " ]";
    }
    
    public String getRequestDateFormat() {
        if (requestDate != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
            return dateFormat.format(requestDate);
        } else {
            return "";
        }
    }

    public String getExpectDateFormat() {
        if (expectDate != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
            return dateFormat.format(expectDate);
        } else {
            return "";
        }
    }

    public String getMsgActionDateFormat() {
        if (msgActionDate != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
            return dateFormat.format(msgActionDate);
        } else {
            return "";
        }
    }

    public String getFinishDateFormat() {
        if (finishDate != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
            return dateFormat.format(finishDate);
        } else {
            return "";
        }
    }
}
